package com.canaan.business.controller.pc.inOutStock;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.enums.BusinessType;
import javax.annotation.Resource;
import com.canaan.business.domain.inOutStock.OutStockBill;
import com.canaan.business.service.inOutStock.IOutStockBillService;
import com.canaan.common.utils.poi.ExcelUtil;
import com.canaan.common.core.page.TableDataInfo;

/**
 * 出库单Controller
 *
 * @author canaan
 * @date 2025-03-29
 */
@Api(tags = "出库单")
@RestController
@RequestMapping("/inOutStock/outStockBill")
public class OutStockBillController extends BaseController {
    @Resource
    private IOutStockBillService outStockBillService;

    /**
     * 查询出库单列表
     */
    @ApiOperation(value = "查询出库单列表")
    @PreAuthorize("@ss.hasPermi('inOutStock:outStockBill:list')")
    @GetMapping("/list")
    public TableDataInfo list(OutStockBill outStockBill) {
        startPage();
        List<OutStockBill> list = outStockBillService.selectOutStockBillList(outStockBill);
        return getDataTable(list);
    }

    /**
     * 导出出库单列表
     */
    @ApiOperation(value = "导出出库单列表")
    @PreAuthorize("@ss.hasPermi('inOutStock:outStockBill:export')")
    @Log(title = "出库单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OutStockBill outStockBill) {
        List<OutStockBill> list = outStockBillService.selectOutStockBillList(outStockBill);
        ExcelUtil<OutStockBill> util = new ExcelUtil<OutStockBill>(OutStockBill.class);
        util.exportExcel(response, list, "出库单数据");
    }

    /**
     * 获取出库单详细信息
     */
    @ApiOperation(value = "获取出库单详细信息")
    @PreAuthorize("@ss.hasPermi('inOutStock:outStockBill:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(outStockBillService.selectOutStockBillById(id));
    }

    /**
     * 获取出库单详细信息 根据托盘编号
     */
    @ApiOperation(value = "获取出库单详细信息")
//    @PreAuthorize("@ss.hasPermi('inOutStock:outStockBill:query')")
    @GetMapping(value = "/byTrayNo/{no}")
    public AjaxResult getInfo(@PathVariable("no") String no) {
        return success(outStockBillService.selectOutStockBillByTrayNo(no));
    }

    /**
     * 新增出库单
     */
    @ApiOperation(value = "新增出库单")
    @PreAuthorize("@ss.hasPermi('inOutStock:outStockBill:add')")
    @Log(title = "出库单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OutStockBill outStockBill) {
        return toAjax(outStockBillService.insertOutStockBill(outStockBill));
    }

    /**
     * 修改出库单
     */
    @ApiOperation(value = "修改出库单")
    @PreAuthorize("@ss.hasPermi('inOutStock:outStockBill:edit')")
    @Log(title = "出库单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OutStockBill outStockBill) {
        return toAjax(outStockBillService.updateOutStockBill(outStockBill));
    }

    /**
     * 删除出库单
     */
    @ApiOperation(value = "删除出库单")
    @PreAuthorize("@ss.hasPermi('inOutStock:outStockBill:remove')")
    @Log(title = "出库单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(outStockBillService.deleteOutStockBillByIds(ids));
    }
}
